<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<meta name="format-detection" content="telephone=no">
<title>今日签到</title>
<link rel="stylesheet" type="text/css" href="css/mui.css"/>
<link rel="stylesheet" type="text/css" href="css/common.css"/>
<link rel="stylesheet" href="css/public.css" />
<link rel="stylesheet" type="text/css" href="css/index.css"/>
<link rel="stylesheet" href="css/signin.css" />
<style>
	.mui-bar{
		box-shadow:none;
		
	}
</style>
</head>

<body class="bg_ff">
	<header class="mui-bar mui-bar-nav" style="background: #CDDFFF;">
	    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
	    <h1 class="mui-title">今日签到</h1>
	</header>
	<div class="mui-content bg_ff">
	    <div class="top flex flex-align-end flex-pack-center flex-warp">
	<div class="out-1 flex flex-align-center flex-pack-center" id="signIn">
		<div class="out-2 flex flex-align-center flex-pack-center">
			<div class="signBtn">
				<strong id="sign-txt">签到</strong>
				<span><em id="sign-count">0</em>天</span>
			</div>
		</div>
	</div>
</div>
<!--<div class="tips">今天已签到，获得1个红包</div>-->
<div class="Calendar">
	<div id="toyear" class="flex flex-pack-center">
		<div id="idCalendarPre">&lt;</div>
		<div class="year-month">
			<span id="idCalendarYear">2018</span>年<span id="idCalendarMonth">6</span>月
		</div>
		<div id="idCalendarNext">&gt;</div>
	</div>
	<table border="1px" cellpadding="0" cellspacing="0">
		<thead>
			<tr class="tou">
				<td>日</td>
				<td>一</td>
				<td>二</td>
				<td>三</td>
				<td>四</td>
				<td>五</td>
				<td>六</td>
			</tr>
		</thead>
		<tbody id="idCalendar">
		</tbody>
	</table>
	
</div>
<p class="padding_12 mg_left20">签到可以获取<span class="code_text"></span>积分哦！</p>
	</div>
<script src="js/mui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-1.7.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/index.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="js/rili.js"></script>
<script language="JavaScript">
	var isSign = false;
	var myday = new Array(); //已签到的数组
			
//获取签到列表
	function signList(){
		$.ajax({
			type:"post",
			url:urlcom + "userCenter/getClockUserList",
			async:true,
			dataType:'json',
			data:{
				userId:localStorage.getItem('userId')
			},
			success:function(res){
				if(res.code==0){
				 
				 res.data.forEach(function(k,v){
				 	
				 	myday.push(k.clockTime/1000)
				 })
				
					
					var cale = new Calendar("idCalendar", {
						qdDay: myday,
						onToday: function(o) {
							o.className = "onToday";
						},
						onSignIn: function (){
							$$("sign-txt").innerHTML = '已签到';
						},
						onFinish: function() {
							$$("sign-count").innerHTML = myday.length //已签到次数
							$$("idCalendarYear").innerHTML = this.Year;
							$$("idCalendarMonth").innerHTML = this.Month; //表头年份
				
						}
					});
					
				}else{
					msg(res.msg)
				}
 			}
	     })
	}signList()
  
   
    var cale = new Calendar("idCalendar", {
		qdDay: myday,
		onToday: function(o) {
			o.className = "onToday";
		},
		onSignIn: function (){
			$$("sign-txt").innerHTML = '已签到';
		},
		onFinish: function() {
			$$("sign-count").innerHTML = myday.length //已签到次数
			$$("idCalendarYear").innerHTML = this.Year;
			$$("idCalendarMonth").innerHTML = this.Month; //表头年份

		}
	});
    
	
	$$("idCalendarPre").onclick = function() {
		cale.PreMonth();
	}
	$$("idCalendarNext").onclick = function() {
		cale.NextMonth();
	}
	
	//签到
	function signIn(){
		$.ajax({
			type:"post",
			url:urlcom + "userCenter/userClock",
			async:true,
			dataType:'json',
			data:{
				userId:localStorage.getItem('userId')
			},
			success:function(res){
				if(res.code==0){
					msg('签到成功')
					isSign = true
				}else{
					msg(res.msg)
				}
 			}
	     })
	}
	//获取签到积分
	function text(){
		$.ajax({
			type:"get",
			url:urlcom + "userCenter/getIntegralSet",
			async:true,
			dataType:'json',
			
			success:function(res){
				if(res.code==0){
					$('.code_text').text(res.data.clock)
				}else{
					msg(res.msg)
				}
 			}
	     })
	}text()
	
	
	console.log(new Date())
	//添加今天签到
	$$("signIn").onclick = function() {
//		this.checkSignIn(new Date(), day[ii]))
		if(isSign == false) {
		    signIn()
			var res = cale.SignIn();
			if(res == '1') {
				$$("sign-txt").innerHTML = '已签到';
				$$("sign-count").innerHTML = parseInt($$("sign-count").innerHTML) + 1;
				isSign = true;
			} else if (res == '2'){
				$$("sign-txt").innerHTML = '已签到';
				msg('今日已签到')
			}
		} else {
			msg('今日已签到')
		}

	}
</script>
 
</body>
</html>